<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css"  tppabs="https://www.layui.site/layui/dist/css/layui.css"  media="all">
	</head>
	<body>
		<form class="layui-form" lay-filter="layui-detail"  style="padding: 10px;" action="../../../updateMemberInfoAdd" method="post">
			<input type="hidden" name="custId" value="custId"/>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">客户名称：</label>
					<div style="width: 300px;" class="layui-input-block">
					  <input type="text" name="custName" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
		    </div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">客户类型：</label>
					<div class="layui-input-block">
						<select name="custTypeId" id="custTypeId" lay-filter="aihao">
						
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">所属地区：</label>
					<div class="layui-input-block">
					  <select name="custAddress" lay-filter="aihao">
						<option value=""></option>
						<option value="益阳">益阳</option>
						<option value="长沙">长沙</option>
					  </select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</label>
					<div class="layui-input-block">
					  <select name="custSex" lay-filter="aihao">
						<option value="女">女</option>
						<option value="男">男</option>
					  </select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">出生日期：</label>
					<div class="layui-input-block">
					  <input type="text" name="custDate" style="width: 212px;" class="layui-input" id="test1" value="">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</label>
					<div class="layui-input-block">
					  <input type="text" style="width: 212px;" name="" lay-verify="title" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">联系电话：</label>
					<div class="layui-input-block">
					  <input type="text" style="width: 212px;" name="custPhone" lay-verify="required|phone" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	号：</label>
					<div class="layui-input-block">
					  <input type="text" style="width: 200px;" readonly="" name="custMenmber" lay-verify="title" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
				  <label class="layui-form-label"></label>
				  <div class="layui-input-inline" id="menmberidJudge">
				    <input type="checkbox" lay-filter="menmberid" title="新增会员" lay-skin="primary"> 
				  </div>
				</div>
			</div>
			<div style="color: red;padding-left: 20px;">(请输入后台会员编号，或者输入新的卡号将自动创建一个会员)</div>
			<div class="layui-form-item layui-form-text">
				<div class="layui-inline" >
					<label class="layui-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</label>
					<div class="layui-input-block" style="width: 300px;">
					  <textarea placeholder="请输入内容" name="custComment" class="layui-textarea"></textarea>
					</div>
				</div>
			</div>
			<div class="layui-form-item" style="text-align: center;">
				<div class="layui-inline">
					<button type="submit" lay-submit="" lay-filter="memberInfo" class="layui-btn">保&nbsp;&nbsp;存</button>
				</div>
				<div class="layui-inline">
					<button type="reset" class="layui-btn">重&nbsp;&nbsp;置</button>
				</div>
			</div>
		</form>
		
		<script src="../../layui/layui.js" charset="utf-8"></script>
		<script>
			layui.use(['form', 'table', 'layer','laydate'], function() {
				var laydate = layui.laydate;
				var tree = layui.tree
				    ,layer = layui.layer
					,table = layui.table
					,form = layui.form
					,$ = layui.jquery;
					
				laydate.render({ elem: '#test1'});
				$(function(){
					$.ajax({
					    url: '/showCustomerTypeInfo',
					    dataType: 'json',
					    type: 'get',
					    success: function (data) {
					        //清空下拉列表的值
					        $('#custTypeId').html('');
					        //循环添加元素
					        $.each(data, function (index, item) {
					            // 下拉菜单里添加元素
					            $('#custTypeId').append(new Option(item.custTypeName,item.custTypeId));
					        });
					        //重新渲染 固定写法
					        layui.form.render("select");
					    }
					});
				})
				$(function(){
					var obj = JSON.parse(parent.memberInfo)
					console.log(obj)
					if(null != obj.custId){
						  //接收一个对象，不转form.val()无法渲染
						form.val();
						form.val('layui-detail',obj);      //渲染表单
						var a = $("input[name=custId]").val()
						if(a !== "custId"){
							$("#menmberidJudge").html(null);
						}
					}
				})
				//是否新增会员复选框
				form.on('checkbox(menmberid)', function(data){
					var Id = data.elem.checked//是否被选中，true或者false
					if(Id == true){
						$.get("../../../searchClientIdInfo",{menId:"menId",table:"menmber_info"},function(obj){
							$("input[name=custMenmber]").val(obj)
						})
					}else if(Id == false){
						$("input[name=custMenmber]").val(null)
					}
				}); 
				
				
				form.on('submit(memberInfo)', function(data){  
					var a = $("input[name=custId]").val()
					if(a == "custId"){
						
						/* 关闭当前弹出层 */
						parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引
						parent.location.reload();
						// contentWindow.location.reload(true);
					}else{
						$.get("../../../updateMemberInfo",data.field,function(row){
							if(row = 1){
								layer.msg('修改成功');
							}else{
								layer.mgs('修改成功');
							}
						})
						/* 关闭当前弹出层 */
						parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引
						parent.location.reload();
					}
					//return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
				
			})			
		</script>
	</body>
</html>
